//
//  UserGuideViewController.m
//  Fangmm
//
//  Created by ChaoZhou on 16/3/28.
//  Copyright © 2016年 com.fangmm. All rights reserved.
//

#import "UserGuideViewController.h"
#import "ACMacros.h"
#import <MobClick.h>
@interface UserGuideViewController ()<UIScrollViewDelegate>
{
    UIPageControl *pageControl;
}
@end

@implementation UserGuideViewController
- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [MobClick beginLogPageView:@"引导页"];
}
- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    [MobClick endLogPageView:@"引导页"];
}
- (void)viewDidLoad
{
    [super viewDidLoad];
    [self initGuide];
    // Do any additional setup after loading the view from its nib.
}
-(void)initGuide
{
    UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, Main_Screen_Width, Main_Screen_Height)];
    scrollView.showsHorizontalScrollIndicator = NO;
    [scrollView setContentSize:CGSizeMake([UIScreen mainScreen].bounds.size.width*4, 0)];
    [scrollView setPagingEnabled:YES];
    scrollView.delegate =self;
    //视图整页显示
    //[scrollView setBounces:NO]; //避免弹跳效果,避免把根视图露出来
    UIImageView *imageview = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, Main_Screen_Width,[UIScreen mainScreen].bounds.size.height)];
    [imageview setImage:[UIImage imageNamed:@"1 身份认证"]];
    [scrollView addSubview:imageview];
    
    UIImageView *imageview1 = [[UIImageView alloc] initWithFrame:CGRectMake(Main_Screen_Width, 0,[UIScreen mainScreen].bounds.size.width,[UIScreen mainScreen].bounds.size.height)];
    [imageview1 setImage:[UIImage imageNamed:@"2 个性匹配"]];
    [scrollView addSubview:imageview1];
    
    UIImageView *imageview2 = [[UIImageView alloc] initWithFrame:CGRectMake(2 * Main_Screen_Width, 0,[UIScreen mainScreen].bounds.size.width,[UIScreen mainScreen].bounds.size.height)];
    [imageview2 setImage:[UIImage imageNamed:@"3 室长定价"]];
    [scrollView addSubview:imageview2];
    
    UIImageView *imageview3 = [[UIImageView alloc] initWithFrame:CGRectMake(3 *Main_Screen_Width, 0,[UIScreen mainScreen].bounds.size.width,[UIScreen mainScreen].bounds.size.height)];
    [imageview3 setImage:[UIImage imageNamed:@"4 组团保障金"]];
    imageview3.userInteractionEnabled = YES;
    //打开imageview3的用户交互;否则下面的button无法响应
    [scrollView addSubview:imageview3];
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];//在imageview3上加载一个透明的button
    [button setTitle:nil forState:UIControlStateNormal];
    [button setFrame:CGRectMake([UIScreen mainScreen].bounds.size.width/2 - 82,self.view.frame.size.height - 100,165,45)];
    [button addTarget:self action:@selector(firstPressed) forControlEvents:UIControlEventTouchUpInside];
    [button setBackgroundColor:[UIColor clearColor]];
    [button setTitle:@"进入" forState:UIControlStateNormal];
    [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [button.layer setCornerRadius:5];
    [button.layer setMasksToBounds:YES];
    [button.layer setBorderWidth:1];
    [button.layer setBorderColor:[[UIColor whiteColor] CGColor]];
    [imageview3 addSubview:button];
    [self.view addSubview:scrollView];
    //pagecontrol
    pageControl = [[UIPageControl alloc]initWithFrame:CGRectMake(([UIScreen mainScreen].bounds.size.width)/2, [UIScreen mainScreen].bounds.size.height - 100, 100, 20)];
    [self.view addSubview:pageControl];
    pageControl.numberOfPages = 4;
    pageControl.backgroundColor = [UIColor redColor];
}
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
    NSInteger page = scrollView.contentOffset.x/[UIScreen mainScreen].bounds.size.width;
    switch (page)
    {
        case 0:
        {
            pageControl.currentPage = 0;
        }
            break;
        case 1:
        {
            pageControl.currentPage = 1;

        }
            break;
        case 2:
        {
            pageControl.currentPage = 2;

        }
            break;
        case 3:
        {
            pageControl.currentPage = 3;
        }
            break;
        default:
            break;
    }
}
-(void)firstPressed
{
    [self.delegate popToRootViewController];
}
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
